import 'package:flutter/material.dart';

class TakeOutBtn extends StatefulWidget {
  /// 自提或则外送按钮
  const TakeOutBtn({
    Key? key,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return new TakeOutBtnState();
  }
}

class TakeOutBtnState extends State {
  int? chooseNum;

  @override
  void initState() {
    super.initState();
    chooseNum = 0;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(3),
      width: 95,
      height: 36,
      decoration: BoxDecoration(
          border: Border.all(width: 1, color: Color.fromRGBO(136, 175, 213, 1)),
          borderRadius: BorderRadius.circular(18)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
              width: 44,
              height: 30,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  color: chooseNum == 0 ? Color.fromRGBO(136, 175, 213, 1) : null,
                  borderRadius: BorderRadius.circular(15)),
              child: new InkWell(
                onTap: () {
                  setState(() {
                    chooseNum = 0;
                  });
                },
                  child:Text(
                '自提',
                style: TextStyle(
                    color: chooseNum == 0 ? Color.fromRGBO(255, 255, 255, 1)
                        : Color.fromRGBO(136, 175, 213, 1), fontSize: 12),
              ))),
          Expanded(child: Container(
              width: 44,
              height: 30,
              alignment: Alignment.center,
              decoration:
              BoxDecoration(color: chooseNum == 1
                  ? Color.fromRGBO(136, 175, 213, 1) : null
                  , borderRadius: BorderRadius.circular(15)),
              child: new InkWell(
                onTap: () {
                  setState(() {
                    chooseNum = 1;
                  });
                },
                child: Text(
                  '外送',
                  style: TextStyle(
                      color: chooseNum == 1 ? Color.fromRGBO(255, 255, 255, 1)
                          : Color.fromRGBO(136, 175, 213, 1), fontSize: 12),
                ),
              )))
        ],
      ),
    );
  }
}
